package ${model.packageName}.${model.modulePackage}.${model.modelL}.controller;

import java.util.List;
import java.util.Date;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.slf4j.Logger;
import com.okrs.framework.aspectj.lang.annotation.Log;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import ${model.packageName}.${model.modulePackage}.${model.modelL}.domain.${model.model};
import ${model.packageName}.${model.modulePackage}.${model.modelL}.service.I${model.model}Service;
import com.okrs.framework.web.controller.BaseController;
import com.okrs.framework.web.page.TableDataInfo;
import com.okrs.framework.web.domain.Message;

/**
 * ${model.comment} 信息操作处理
 * 
 * @author ${model.author}
 * @date ${date}
 */
@Controller
@RequestMapping("/${model.modulePackage}/${model.modelL}")
public class ${model.model}Controller extends BaseController
{

    private static final Logger log = LoggerFactory.getLogger(${model.model}Controller.class);
    private String prefix = "${model.modulePackage}/${model.modelL}";
	
	@Autowired
	private I${model.model}Service ${model.modelL}Service;
	
	@GetMapping()
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:view")
	public String ${model.modelL}()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询${model.comment}列表
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:list")
	@GetMapping("/list")
	@ResponseBody
	public TableDataInfo list(${model.model} ${model.modelL})
	{
		startPage();
        List<${model.model}> list = ${model.modelL}Service.select${model.model}List(${model.modelL});
		return getDataTable(list);
	}
	
	/**
	 * 新增${model.comment}
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:add")
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改${model.comment}
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, Model model)
	{
		${model.model} ${model.modelL} = ${model.modelL}Service.select${model.model}ById(id);
		model.addAttribute("${model.modelL}", ${model.modelL});
	    return prefix + "/edit";
	}
	
	/**
	 * 保存${model.comment}
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:save")
	@PostMapping("/save")
	@Log(title = "${model.comment}", action = "${model.comment}--保存")
	@ResponseBody
	@Transactional(rollbackFor={RuntimeException.class, Exception.class})
	public Message save(${model.model} ${model.modelL})
	{ 
		
		if (${model.modelL}Service.save${model.model}(${model.modelL}) > 0)
		{
			return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 详情${model.comment}
	 */ 
	@GetMapping("/detail/{id}")
	public String detail(@PathVariable("id") Integer id, Model model)
	{
		${model.model} ${model.modelL} = ${model.modelL}Service.select${model.model}ById(id);
		model.addAttribute("${model.modelL}", ${model.modelL});
	    return prefix + "/show";
	}
	/**
	 * 删除${model.comment}
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:remove")
	@PostMapping( "/remove/{id}")
	@Log(title = "${model.comment}", action = "${model.comment}--删除")
	@ResponseBody
	@Transactional(rollbackFor={RuntimeException.class, Exception.class})
	public Message remove(@PathVariable("id") Integer id)
	{
		if (${model.modelL}Service.delete${model.model}ById(id) > 0)
		{
		    return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 批量删除${model.comment}
	 */
	@RequiresPermissions("${model.modulePackage}:${model.modelL}:batchRemove")
	@PostMapping( "/batchRemove")
	@Log(title = "${model.comment}", action = "${model.comment}--批量删除")
	@ResponseBody
	@Transactional(rollbackFor={RuntimeException.class, Exception.class})
	public Message remove(@RequestParam("ids[]") Integer[] ids)
	{
		int rows = ${model.modelL}Service.batchDelete${model.model}(ids);
		if (rows > 0)
        {
            return Message.success();
        }
        return Message.error();
	}
	
}
